package com.tjsinfo.tjsoa.messageImportant.bo;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.messageImportant.dao.IMessageImportantMainDAO;
import com.tjsinfo.tjsoa.messageImportant.vo.MessageImportantMain;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;


public class MessageImportantMainBo implements IMessageImportantMainBo {
	private IQbcDao qbcDao;
	private IMessageImportantMainDAO importantMainDAO;

	public IMessageImportantMainDAO getImportantMainDAO() {
		return importantMainDAO;
	}

	public void setImportantMainDAO(IMessageImportantMainDAO importantMainDAO) {
		this.importantMainDAO = importantMainDAO;
	}

	public IQbcDao getQbcDao() {
		return qbcDao;
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.MessageImportant.MessageImportant_Main.IMessageImportantMainBo#setQbcDao(com.tjsinfo.tjsoa.Dao.IQbcDao)
	 */
	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}
	
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.MessageImportant.MessageImportant_Main.IMessageImportantMainBo#findBySendUser(com.tjsinfo.tjsoa.system.TjsUser.TjsUser)
	 */
	public List findBySendUser(Integer userid,String sql,String order) {
		DetachedCriteria criteria = DetachedCriteria.forClass(MessageImportantMain.class);
		criteria.add(Restrictions.eq("sendUserId", userid));
		criteria.add(Restrictions.eq("sendSql", sql));
		criteria.add(Restrictions.eq("state", 0));
		if (order!=null && !"".equals(order)) {
			if ("asc".equals(order)) {
				criteria.addOrder(Order.asc("datetime"));
			}else {
				criteria.addOrder(Order.desc("datetime"));
			}
		}else {
			criteria.addOrder(Order.desc("datetime"));
		}
		List list = qbcDao.getCriteria(criteria);
		return list;
	}
	
	public MessageImportantMain findById(String id) {
		DetachedCriteria criteria = DetachedCriteria.forClass(MessageImportantMain.class);
		criteria.add(Restrictions.eq("id", id));
		List list = qbcDao.getCriteria(criteria);
		return (MessageImportantMain) list.iterator().next();
	}
	
	public void delete(String id) {
		MessageImportantMain main = this.findById(id);
		main.setState(1);
		importantMainDAO.update(main);
	}
//MessageImportantMain增加方法
	public String save(MessageImportantMain main) {
		String i =null; 
		i=importantMainDAO.save(main);
		return i;
	}
	
	public void update(MessageImportantMain main) {
		importantMainDAO.update(main);
	}
}
